define(['common/js/boss-frame-angular-dev-0.1'], function () {
    diretiveModule.directive('timePeriodSelect', function () {
        return {
            scope: false,
            restrict: "E",
            replace: true,
            controller : function($scope,$attrs){
                var minView = $attrs.minView;
                if(typeof (minView)=='undefined'){
                    $scope.timeDateOption = {
                        format : 'yyyy-mm-dd',
                        minView : 2
                    };
                }else{
                    $scope.timeDateOption = {
                        format : 'yyyy-mm-dd hh:ii:ss',
                        minView : 0
                    };
                }

            },
            template: '<tmp>\n    <button class="btn btn-success" ng-click="searchByDay()" style="margin-right:4px;">本日</button>\n    <button class="btn btn-success" ng-click="searchByWeek()" style="margin-right:4px;">本周</button>\n    <button class="btn btn-success mr10" ng-click="searchByMonth()">本月</button>\n\n    <grid-condition-date class="mr10"\n                         condition-name="startTime"\n                         date-format="yyyy-mm-dd"\n                         condition-option="timeDateOption"\n                         condition-tip="开始时间"></grid-condition-date>\n    <grid-condition-date class="mr10"\n                         condition-name="endTime"\n                         date-format="yyyy-mm-dd"\n                         condition-option="timeDateOption"\n                         condition-tip="结束时间"></grid-condition-date>\n</tmp>',
            link : function(scope,elem,attrs){
                var searchByDateStr = attrs.searchByDate;
                if(!searchByDateStr){
                    console.error("请设置属性search-by-date");
                    return;
                }

                scope.searchByDay = function(){
                    scope[searchByDateStr]('day');
                };
                scope.searchByWeek = function(){
                    scope[searchByDateStr]('week');
                };
                scope.searchByMonth = function(){
                    scope[searchByDateStr]('month');
                };
            }
        };
    });

});